<html>
<head>
<script src="../resources/js-test.js"></script>
<script src="../resources/user-gesture-utils.js"></script>
<script src="vibration-utils.js"></script>
</head>
<body>
<h4 id="test"></h4>
<script>
description('Tests for how patterns are handled in the Vibration API.');

// Simulates a user click for vibrate to be allowed.
var element = document.getElementById("test");
simulateUserClick(element.offsetLeft + 2, element.offsetTop + 2);

// A trailing pause is discarded from a pattern i.e. patterns of even
// non-zero length are truncated by 1.
shouldBeTrue("navigator.vibrate(newPattern(1, 4))");
shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(navigator), newPattern(1, 3))");
shouldBeTrue("internals.isVibrating(navigator)");
stopVibration();

// Maximum pattern length.
shouldBeTrue("navigator.vibrate(newPattern(1, 99))");
shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(navigator), newPattern(1, 99))");
shouldBeTrue("internals.isVibrating(navigator)");
stopVibration();

// The pattern is longer than supported. It is truncated and execution proceeds.
shouldBeTrue("navigator.vibrate(newPattern(1, 200))");
shouldBeTrue("areArraysEqual(internals.pendingVibrationPattern(navigator), newPattern(1, 99))");
shouldBeTrue("internals.isVibrating(navigator)");
stopVibration();

</script>
</body>
</html>
